﻿using System.Collections.Generic;

namespace Magellan.Routing
{
    public class PathIterator
    {
        private readonly Queue<string> _partQueue = new Queue<string>();

        public PathIterator(string path)
        {
            var parts = path.SplitUrlPath();
            foreach (var part in parts)
            {
                _partQueue.Enqueue(part);
            }
        }

        public bool IsAtEnd
        {
            get { return _partQueue.Count == 0; }
        }

        public string Next()
        {
            return _partQueue.Count == 0 
                ? "" 
                : _partQueue.Dequeue();
        }

        public string ReadAll()
        {
            var result = string.Join("/", _partQueue.ToArray());
            _partQueue.Clear();
            return result;
        }
    }
}